package com.hfxt.util;

import java.io.Serializable;
import java.util.List;

/**
 * 超市账单管理系统 PageUtil
 * 分页工具类
 */
public class PageUtil<T> implements Serializable {
    private static final long serialVersionUID = -1975339729948473372L;

    //当前页码
    private Integer pageIndex;
    //页容量
    private Integer pageSize;
    //总记录数
    private Integer totalCount;
    //总页数
    private Integer totalPageNum;
    //分页查询得到的集合
    private List<T> lists;

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        if (totalCount < 0) {
            this.totalCount = 0;
        } else {
            this.totalCount = totalCount;
            //给定的总记录数得到总页数
            totalPageNum = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
        }
        if (totalCount == 0) {
            pageIndex = 0;
        }
    }

    public Integer getTotalPageNum() {
        return totalPageNum;
    }

    public void setTotalPageNum(Integer totalPageNum) {
        this.totalPageNum = totalPageNum;
    }

    public List<T> getLists() {
        return lists;
    }

    public void setLists(List<T> lists) {
        this.lists = lists;
    }

    @Override
    public String toString() {
        return "PageUtil{" +
                "pageIndex=" + pageIndex +
                ", pageSize=" + pageSize +
                ", totalCount=" + totalCount +
                ", totalPageNum=" + totalPageNum +
                ", lists=" + lists +
                '}';
    }
}
